<template>
  <div class="container">
    <div class="top">
      <div>{{formattedDateTime }}</div>
      <div class="top-btn">
        <el-icon style="margin-right: 10px">
          <SwitchButton />
        </el-icon>
        退出
      </div>
    </div>
    <div class="header">
      <el-row align="middle">
        <el-col :span="6">
          <div class="jsc" @click="openUrl(0)">
            <span class="gradient-font" style="cursor: pointer">驾驶舱</span>
            <el-icon class="gradient-font">
              <ArrowRightBold />
            </el-icon>
          </div>
        </el-col>
        <el-col :span="12">
          <h1 class="gradient-font" style="padding-top: 40px;text-align: center">{{ title }}</h1>
        </el-col>
        <el-col :span="6">
          <div class="qiye">
            <div style="cursor: pointer" @click="openUrl(1)">
              <el-icon>
                <Setting />
              </el-icon>
              企业服务
            </div>
            <div>
              <el-icon>
                <Setting />
              </el-icon>
              平台设置
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="body">
      <el-row :gutter="20">
        <template v-for="item in tableData">
          <el-col :span="item.col">
            <div class="box">
              <div>
                <div class="gradient-font">{{ item.title }}</div>
                <el-image style="width: 149px;height: 116px;margin-left: 20px;margin-top: 20px"
                  :src="item.icon"></el-image>
              </div>
              <div>
                <ul>
                  <li v-for="val in item.child" :class="val.show ? 'show' : ''" @click="navTo(val)">
                    {{ val.title }}
                  </li>
                </ul>
              </div>
            </div>
          </el-col>
        </template>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import utils from "@/utils/index"
import {useRouter} from 'vue-router'

const router = useRouter()

const title = import.meta.env.VITE_BASE_TITLE
const navTo = (val) => {
  if (val.url) {
    window.open(val.url)
  } else {
    router.push(val.path)
  }

}

const urls = [
  'https://nthqfzx.huzhou.gov.cn/hzscreen/#/index',
  'https://smrq.huzjkjt.com:1443'
]

const formattedDateTime = ref('');

// 更新日期和时间的函数
const updateDateTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');
  formattedDateTime.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};

// 组件挂载后开始定时更新时间
onMounted(() => {
  const intervalId = setInterval(updateDateTime, 1000);
  // 组件卸载时清除定时器
  onUnmounted(() => {
    clearInterval(intervalId);
  });
  // 初始调用一次，确保页面加载时显示当前时间
  updateDateTime();
});
const openUrl = (k) => {
  window.open(urls[k])
}

const tableData = ref([
  {
    "title": "经济运行中心",
    "icon": utils.getAssetsFile('jjyxzx.png'),
    "col": 6,
    "child": [
      {
        "title": "农业经济",
        "show": false,
        "path": "/"
      },
      {
        "title": "工业经济",
        "show": true,
        "path": "/newEcoIndicators"
      },
      {
        "title": "服务业经济",
        "show": false,
        "path": "/"
      },
      {
        "title": "数字经济",
        "show": true,
        "path": "/digitalEconomy"
      }
    ]
  },
  {
    "title": "产品监测中心",
    "icon": utils.getAssetsFile('cyjczx.png'),
    "col": 6,
    "child": [
      {
        "title": "产业地图",
        "show": false,
        "path": "/"
      },
      {
        "title": "产业分析",
        "show": true,
        "path": "/industryAnalysis"
      },
      {
        "title": "入链找链",
        "show": true,
        "path": "/findChain"
      }
    ]
  },
  {
    "title": "企业智治中心",
    "icon": utils.getAssetsFile('qyzzzx.png'),
    "col": 6,
    "child": [
      {
        "title": "态势感知",
        "show": true,
        "path": "/situationalAwareness"
      },
      {
        "title": "企业培育",
        "show": true,
        "path": "/enterpriseCultivation?type=fourEnterprises"
      },
      {
        "title": "企业画像",
        "show": true,
        "path": "/corporateProfile"
      }
    ]
  },
  {
    "title": "招商管理中心",
    "icon": utils.getAssetsFile('zsglzx.png'),
    "col": 6,
    "child": [
      {
        "title": "商事登记",
        "show": true,
        "path": "",
        "url": "https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2002388475/reserved/index.html#/market-registration?siteCode"
      },
      {
        "title": "投资审批",
        "show": true,
        "path": "",
        "url": "https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2002388475/reserved/index.html#/project-approval?siteCode"
      },
      {
        "title": "招商预警监测",
        "show": false,
        "path": "/"
      }
    ]
  },
  {
    "title": "政策管理中心",
    "icon": utils.getAssetsFile('zcglzx.png'),
    "col": 8,
    "child": [
      {
        "title": "政策超市",
        "show": true,
        "path": "/policySupermarket"
      },
      {
        "title": "政策智配",
        "show": true,
        "path": "/policyIntelligenceMatching?type=policyWisdom"
      },
      {
        "title": "政策智评",
        "show": false,
        "path": "/"
      }
    ]
  },
  {
    "title": "要素资源中心",
    "icon": utils.getAssetsFile('yszy.png'),
    "col": 8,
    "child": [
      {
        "title": "数据资源目录",
        "show": true,
        "path": "/dataResourceCatalog?type=dataOverview"
      },
      {
        "title": "土地要素",
        "show": true,
        "path": "/landElements"
      },
      {
        "title": "资源要素",
        "show": true,
        "path": "/resourceElements"
      },
      {
        "title": "资金要素",
        "show": false,
        "path": "/"
      }
    ]
  },
  {
    "title": "应用工具中心",
    "icon": utils.getAssetsFile('yygj.png'),
    "col": 8,
    "child": [
      {
        "title": "科创服务",
        "show": true,
        "path": "/",
        "url":"https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2002388475/reserved/index.html#/innovation-service?siteCode"
      },
      {
        "title": "表单中心",
        "show": false,
        "path": "/"
      },
      {
        "title": "报告中心",
        "show": false,
        "path": "/"
      }
    ]
  },
])
</script>
<style lang="scss" scoped>
.top {
  width: 100%;
  height: 100px;
  padding: 0 20px;
  box-sizing: border-box;
  color: #9ccdff;
  background: url('@/assets/images/oneBg.png') no-repeat center center / cover;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-btn {
  cursor: pointer;
  padding: 2px 10px;
  font-size: 18px;
  display: flex;
  align-items: center;
}

.header {
  color: #FFFFFF;
  height: 230px;
  background: url('@/assets/images/twoBg.png') no-repeat center center / 100% 100%;

  .jsc {
    margin: 0 auto;
    width: 320px;
    height: 70px;
    line-height: 85px;
    background: url('@/assets/images/jscno.png') no-repeat center center / 100% 100%;
    text-align: right;
    padding-right: 20px;
    box-sizing: border-box;

    >span {
      font-size: 24px;
      font-weight: 700;
      margin-right: 20px;
    }

    &:hover {
      filter: brightness(120%);
    }
  }

  .qiye {
    cursor: pointer;
    margin: 0 auto;
    width: 128px;
    height: 100px;
    display: flex;
    color: #d5eaff;
    flex-direction: column;
    justify-content: space-between;

    >div {
      height: 45px;
      padding: 0 20px;
      line-height: 45px;
      border: 1px solid #0b63b7;
      border-radius: 5px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    >div:hover {
      background-color: rgba(90, 223, 251, .1);
    }
  }
}


.body {
  padding: 0 40px 40px 40px;

  .box {
    width: 100%;
    height: 280px;
    box-sizing: border-box;
    display: flex;
    background: url('@/assets/images/top_no.png') no-repeat center center / 100% 100%;
    padding: 35px;

    >div:first-child {
      width: 50%;
      height: 100%;
      font-size: 24px;
      font-weight: bold;
      text-align: left;
    }

    >div:last-child {
      width: 50%;
      height: 100%;

      >ul {
        color: #ffffff;
        padding-top: 5px;
        padding-left: 50px;
        text-align: center;

        >li {
          cursor: pointer;
          margin: 10px 0;
          width: 100%;
          height: 40px;
          line-height: 40px;
          font-size: 16px;
          font-weight: 700;
          color: rgba(255, 255, 255, .5);
          ;
          box-sizing: border-box;
          background-image: linear-gradient(-90deg, rgba(1, 94, 234, .05), rgba(0, 192, 250, .5));
          position: relative;
        }

        >li::before {
          position: absolute;
          content: '';
          top: 0;
          left: -25px;
          width: 25px;
          height: 40px;
          border-top-left-radius: 20px;
          border-bottom-left-radius: 20px;
          background: linear-gradient(-45deg, #262370 0%, #0282b4 100%);
          opacity: .3;
        }

        .show {
          color: #ffffff;
        }

        .show:hover {
          color: #faab32;
        }

        .show:hover::before {
          background: linear-gradient(-45deg, #f46c48 0%, #fac429 100%);
          opacity: 1;
        }
      }
    }
  }
}
</style>
